<template>
  <div
    id="ckddDetail"
    v-loading="loading"
  >
    <v-tableTitle
      :btnConfig="btnConfig"
      :tableSelectData="tableSelectData"
      @exportFile="exportFile"
      :title="$t('out.outboundInfo')"
    ></v-tableTitle>
    <v-table
      :pageSize="pageSize"
      :page="page"
      :tableConfig="tableConfig"
      :tableData="tableData"
      :total="total"
      @findData="getTableData"
      @getTableData="getTableData"
      @searhData="searhData"
      @selectData="selectData"
      @setdialog="setdialog"
      @upData="getTableData"
      :hasEdit="false"
      ref="table"
    ></v-table>
  </div>
</template>

<script type="text/ecmascript-6">
import tableTitle from "commons/TableTitle";
import table from "commons/Table";
import baseMixin from "@/mixins/BaseMixin";
import config from "./Config";
import bus from "../../../../bus/bus"

export default {
  name: "ckddDetail",
  mixins: [baseMixin, config],
  data () {
    return {
      loading: false,
      tableConfig: [
        {
          label: this.$t('out.orderkey'),
          prop: "orderkey",
          input: "input",
        },
        {
          label: this.$t('in.externreceiptkey2'),
          prop: "externorderkey",
          input: "input",
        },
        {
          label: this.$t('outbound.userlinenumber'),
          prop: "orderlinenumber",
          input: "input",
        },
        {
          label: this.$t('config.shipper'),
          prop: "storerkey",
          input: "input",
        },
        {
          label: this.$t('config.sku'),
          prop: "sku",
          input: "input",
        },
        {
          label: this.$t('common.desc'),
          prop: "skudescr",
          input: "input"
        },
        {
          label: this.$t('config.packaging'),
          prop: "packkey",
          input: "input",
        },
        {
          label: this.$t('in.qtyordered'),
          prop: "originalqty",
          input: "input",
        },
        {
          label: this.$t('common.status'),
          prop: "status",
          input: "select",
          options: this.getOptions("queryOrderStatusDropDown")
        },
        {
          label: this.$t('in.surplusqty'),
          prop: "openqty",
          input: "input",
        },
        {
          label: this.$t('out.originalqty'),
          prop: "originalqty",
          input: "input",
        },
        {
          label: this.$t('outbound.qtyallocated'),
          prop: "qtyallocated",
          input: "input",
        },
        {
          label: this.$t('outbound.qtypicked'),
          prop: "qtypicked",
          input: "input",
        },
        {
          label: this.$t('out.shippedqty'),
          prop: "shippedqty",
          input: "input",
        },
        {
          label: this.$t('out.qtypreallocated'),
          prop: "qtypreallocated",
          input: "input",
        },
        {
          label: this.$t('config.allocaStrategy'),
          prop: "newallocationstrategy",
          input: "select",
          options: this.getOptions("queryNewallocationstrategyDropDown"),
        },
        {
          label: this.$t('out.preallocatestrategykey'),
          prop: "preallocatestrategykey",
          input: "select",
          options: this.getOptions("queryPreallocatestrategyDropDown"),
        },
        {
          label: this.$t('config.strategykey'),
          prop: "allocatestrategykey",
          input: "select",
          options: this.getOptions("queryAllocatestrategyDropDown"),
        },
        {
          label: this.$t('app.createDate'),
          prop: "adddate",
          input: "date",
        },
        {
          label: this.$t('app.createName'),
          prop: "addwho",
          input: "input",
        },
        {
          label: this.$t('app.editDate'),
          prop: "editdate",
          input: "date",
        },
        {
          label: this.$t('app.editName'),
          prop: "editwho",
          input: "input",
        },
      ],
      tableData: [],
      pageSize: 10,
      page: 1,
      total: 0,
      tableSelectData: [],
      tableSearhData: {},
    };
  },
  computed: {
    btnConfig () {
      return [
        { label: this.$t('common.export'),certigier: !this.btnPermNameList.includes('WM021001'), disabled: true, invalid: "exportFile" },
      ]
    }
  },
  created () {
  },
  methods: {
    //导出
    async exportFile (data) {
      try {
        let res = await this.$api.post('/exportOrderdetailList', data, { responseType: 'blob' })
        if (window.navigator.msSaveBlob) {
          var blobObject = new Blob([res.data]);
          window.navigator.msSaveBlob(blobObject, this.$t('out.outboundInfo') + '.xls');
        } else {
          var blob = new Blob([res.data], { type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document;charset=utf-8' });
          var filename = this.$t('out.outboundInfo') + '.xls';
          var downloadElement = document.createElement('a');
          var href = window.URL.createObjectURL(blob); //创建下载的链接
          downloadElement.style.display = 'none';
          downloadElement.href = href;
          downloadElement.download = filename; //下载后文件名
          document.body.appendChild(downloadElement);
          downloadElement.click(); //点击下载
          document.body.removeChild(downloadElement); //下载完成移除元素
          window.URL.revokeObjectURL(href); //释放掉blob对象
        }
      } catch (e) {
        this.$message.error(e);
      } finally {
        
      }
    },
    selectData (data) {
      this.tableSelectData = data;
    },

    //获取table数据
    async getTableData (page, data) {
      try {
        let res = await this.$api.post(`/orderdetailList/${page}`, data);
        
          this.loading = false;
          this.tableData = res.page.list;
          this.page = res.page.curpage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      } catch (e) {
        this.$message.error(e);
      }
    },
    //搜索的值
    searhData (data, up) {
      if (!up) {
        this.tableSearhData = data;
      } else {
        this.tableSearhData = data;
        this.getTableData(1, this.tableSearhData);
      }
    },
    //设置弹框
    setdialog (data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'umenuRunDeawer' });
    },
  },
  mounted () {
    this.$store.commit("setSkip", {});
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setTemporary", "");
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  watch: {
    tableSelectData (data) {
      if (data.length > 0) {
        this.deleteStatus = false;
      } else {
        this.deleteStatus = true;
      }
    }
  },
  components: {
    "v-tableTitle": tableTitle,
    "v-table": table,
  }
};
</script>

<style scoped>
#usermgr {
  width: 100%;
  height: 99%;
  padding-top: 6px;
}
</style>
